package com.briup.server.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.common.response.Result;
import com.briup.server.domain.bean.Labs;
import com.briup.server.domain.dto.ConditionQueryDTO;
import com.briup.server.domain.vo.LabsDetailVO;
import com.briup.server.service.LabsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "实验室相关接口")
@RestController
@RequestMapping("/labs")
@RequiredArgsConstructor
public class LabController {
    private final LabsService labsService;

    @Operation(summary = "获取所有实验室列表")
    @GetMapping("/list")
    public Result<List<Labs>> getAllLabs() {
        return Result.success(labsService.list())
                .apply("获取成功");
    }

    @Operation(summary = "分页条件查询实验室列表")
    @GetMapping("/page")
    public Result<Page<LabsDetailVO>> getLabsByPage(ConditionQueryDTO queryDTO) {
        Page<LabsDetailVO> page = labsService.pageQuery(queryDTO);
        return Result.success(page)
                .apply("获取成功");
    }

    @Operation(summary = "新增实验室")
    @PostMapping("/save")
    public Result<?> saveLabs(@RequestBody Labs labs) {
        labsService.saveOrUpdate(labs);
        return Result.success();
    }

    @Operation(summary = "修改实验室")
    @PutMapping("/update")
    public Result<?> updateLabs(@RequestBody Labs labs) {
        labsService.saveOrUpdate(labs);
        return Result.success();
    }

    @Operation(summary = "删除实验室")
    @DeleteMapping("/delete")
    public Result<?> deleteLabs(@RequestBody List<String> ids) {
        labsService.removeByIds(ids);
        return Result.success();
    }
}
